﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using FrbaBus.Properties;
using System.Collections;
using System.Data;

namespace FrbaBus
{
    public class DbHelper
    {
        internal static SqlDataReader ExecuteQuery(string query)
        {
            return getSqlCommand(query).ExecuteReader();
        }

        internal static void ExecuteNonQuery(string query)
        {
            getSqlCommand(query).ExecuteNonQuery();
        }
   
        internal static int ExecuteScalar(string query) {

            return Convert.ToInt32(getSqlCommand(query).ExecuteScalar());
        
        }

        private static SqlCommand getSqlCommand(string query)
        {
            string sConnectionString = Settings.Default.GD1C2013ConnectionString;
            SqlConnection connection = new SqlConnection(sConnectionString);
            connection.Open();
            SqlCommand sqlCommand = new SqlCommand(query, connection);
            sqlCommand.CommandTimeout = 1000;


            return sqlCommand;
        }

    }
}


